<?php

	if( !isset($_COOKIE["username"]) ){
		header("Location:login.php");
	}else{
		setcookie("username", $_COOKIE["username"],time() + 900);
	}
	include_once 'json_function.php';
	$ini_array = parse_ini_file("config/config.ini");
	
	$conn = @mysqli_connect($ini_array["host"], $ini_array["username"], $ini_array["password"], $ini_array["db_name"]) or die("cann't connect the mysql db");
	mysqli_set_charset($conn, "utf8");
	ini_set('default_charset', "UTF-8");
	$No = mysqli_real_escape_string($conn,$_POST["no"]);
	
	$getSubCodeSql = "select no, code_number, parent_number, description from icd9_code where parent_number=".$No;
	$getSubCodeResult = mysqli_query($conn, $getSubCodeSql);
	//echo $getSubCodeSql;
	$data = "{\"data\":[";
	
	$index = 0;
	while( $row = mysqli_fetch_array($getSubCodeResult)){
		$noInDB = $row["no"];
		$codeNumber = $row["code_number"];
		$parentNumber = $row["parent_number"];
		$description = $row["description"];
		if( $index != 0 ){
			$data .= ",";
			
		}
		$data .= "{\"no\":\"".$noInDB."\",";
		$data .= "\"codeNumber\":\"".$codeNumber."\",";
		$data .= "\"parentNumber\":\"".$parentNumber."\",";
		$data .= "\"description\":\"".$description."\"}";
		$index++;
	}
	$data .= "]}";
	
	echo JsonCharFilter($data);
	
?>